#include<bits/stdc++.h>
#define int long long
#define lowbit(x) (x&(-x))
#define rep(i,l,r) for(int i=(l);i<=(r);++i)
#define IN(x) freopen(#x".in","r",stdin)
#define OUT(x) freopen(#x".out","w",stdout)
template<class T=int>
inline T read(){
    T x=0; char c=0; bool sgn=0;
    for(;!isdigit(c);c=getchar())sgn|=(c=='-');
    for(;isdigit(c);c=getchar())x=(x<<3)+(x<<1)+(c^48);
    return sgn?-x:x;
}
template<class T>
inline void write(T x){
    static char c[45]; unsigned p=0;
    if(x<0)putchar('-'),x=-x;
    do c[++p]=(x%10)^48,x/=10; while(x);
    while(p)putchar(c[p--]);
}
inline void write(char c){putchar(c);}
template<class T,class ...U>
inline void write(T x,U ...t){
    write(x),write(t...);
}
using namespace std;
const int N=1e5+10;
int T,n,m,L,V,d[N],v[N],a[N],p[N];
int ans1,ans2;
typedef pair<int,int> pii;
pii seg[N];
void Calc(int i){
    int l,r,mid,st,ed;
    if(v[i]>V){
        l=1,r=m,mid;
        while(l<r){
            mid=l+r>>1;
            if(p[mid]>=d[i])r=mid;
            else l=mid+1;
        }
        if(p[l]<d[i])return;
        st=l;
        if(a[i]>=0)seg[++ans1]={st,m};
        else{
            l=st,r=m,mid;
            int t=V*V-v[i]*v[i]+d[i]*2*a[i];
//            cout<<t<<endl;
            while(l<r){
                mid=l+r+1>>1;
//                cerr<<l<<' '<<r<<' '<<mid<<' '<<p[mid]<<endl;
                if(t<p[mid]*2*a[i])l=mid;
                else r=mid-1;
            }
            if(t>=p[l]*2*a[i])return;
            ed=l;
            seg[++ans1]={st,ed};
        }
    }
    else{
        if(a[i]>0){
            l=1,r=m,mid;
            int t=V*V-v[i]*v[i]+d[i]*2*a[i];
//            cout<<t<<endl;
            while(l<r){
                mid=l+r>>1;
//                cerr<<l<<' '<<r<<' '<<mid<<' '<<p[mid]<<endl;
                if(t<p[mid]*2*a[i])r=mid;
                else l=mid+1;
            }
            if(t>=p[l]*2*a[i])return;
            st=l;
            seg[++ans1]={st,m};
        }
    }
}
signed main(){
    IN(detect);
    OUT(detect);
//    scanf("%lld",&T);
T=read();
    while(T--){
        n=read(),m=read(),L=read(),V=read();
//        scanf("%lld%lld%lld%lld",&n,&m,&L,&V);
        ans1=ans2=0;
        for(int i=1;i<=n;++i){
            d[i]=read(),v[i]=read(),a[i]=read();
//            scanf("%lld%lld%lld",&d[i],&v[i],&a[i]);
        }
        for(int i=1;i<=m;++i){
            p[i]=read();
//            scanf("%lld",&p[i]);
        }

        for(int i=1;i<=n;++i){
            Calc(i);//cout<<seg[ans1].first<<' '<<seg[ans1].second<<endl;
        }
//        sort(seg+1,seg+ans1+1);
//        cout<<"BP\n";
//        for(int i=1;i<=ans1;++i)cout<<seg[i].first<<' '<<seg[i].second<<endl;
//        cout<<"BP\n";
//        write(ans1,' ');
        sort(seg+1,seg+ans1+1);
        if(ans1)ans2=1;
        int minR=seg[1].second;
        for(int i=2;i<=ans1;++i){
//            cout<<i<<' '<<seg[i].first<<' '<<seg[i].second<<' '<<minR<<endl;
            if(seg[i].first>minR)++ans2,minR=seg[i].second;
            else minR=min(minR,seg[i].second);
        }
        write(ans1,' ',m-ans2,'\n');
//        write(ans2,'\n');
//        write(m-ans2,'\n');
//        printf("%lld %lld\n",ans1,m-ans2);
    }
    return 0;
}
